package com.ymkyve.complex.servlet;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 转发servlet
 * 两种 转发方式
 * response.sendRedirect<br>
 * request.getRequestDispatcher().forward()<br>
 * @author wb_liang.gao
 *
 */
public class TimeDispatcherServlet extends HttpServlet {

    private static final long serialVersionUID = 3248125742557442828L;

    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        //请求地址： http://127.0.0.1:8080/test.dispatcher
        
        //站外重定向        
        //response.sendRedirect("http://news.163.com/");        

        //站内转发   转发到 TimeHttpServlet
        RequestDispatcher dispatcher = request.getRequestDispatcher("/test.time");
        dispatcher.forward(request, response);
        
//        request.getRequestDispatcher("/test.time").forward(request, response);
//        request.getRequestDispatcher("/test.time").include(request, response);
    }

    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doGet(request, response);
    }
}
